{extend name="public/base"/}
{block name="style"}
<link href="__PUBLIC__/ieasy/css/recently.css" rel="stylesheet" type="text/css">
{/block}
{block name="body"}
<div id="console_main"></div>


<!-- 这是正文 body_sytle_girl -->

<div class="body_sytle">
	<div class="i_nav_fixed_box">
	<div class="i_nav_box">
        		<a href="/personal/info.html" class="i_nav_user_img"><img alt="" src="{if session('user_auth.uid')>0}{$Think.session.user_auth.uid|get_avatar}{else}__PUBLIC__/ieasy/images/homeuser.png{/if}" /></a>
        		<div class="i_nav_list">
					<a href="/?channel=1" class=nav_but>
					<strong>男生</strong>
					<span></span>
					</a>
					<a href="/?channel=2" class=nav_but>
					<strong>女生</strong>
					<span></span>
					</a>
					<a href="/personal/history" class='nav_but hover'>
				<strong>最近阅读</strong>
				<span></span>
			</a>
		</div>
	</div>
</div>
	<!--i_nav_box 顶部导航-->
	<div class="r_img_list_box">
		<div class="r_img_edit_box">
			<div class="r_book_num">
				<strong totalnum="3" id="num">共0本</strong>
				<em>选中0本</em>
			</div>
			<div class="r_img_edit_but_box" >
				<a href="javascript:;" class="r_img_edit_open">管理</a>
				<a href="javascript:;" class="r_img_edit_close">取消</a>
				<a href="javascript:;" class="r_img_edit_remove">确定删除</a>
			</div>
		</div>

		<ul class="r_img_ul" id="recent_ul"></ul>
		<!--r_img_ul 最近阅读列表 r_img_remove_select-->
		<div class="loading_box" id="quanbu"><span>已显示全部图书</span></div>
	</div>
		<!--r_img_list 编辑最近阅读列表 r_img_list_edit_remove r_img_list_edit -->

	<div class="content_null_box content_null_top_border" id="kong"  style="display:none;">
		<img src="/public/ieasy/img/icon_5.png?v=2.1.49" style="width: .72rem;" />
		<span>你还没有阅读记录</span>
	</div>

	<div class="r_img_list_other"  style="display:block;" >
		<div class="r_img_list_other_tit">
			<h2>为你推荐</h2>
		</div>
		<ul class="r_img_ul" id="tj1"></ul>
	</div>
</div>


<script type="text/html" id="list2">
        <% for(var i = 0; i < data.length; i++){ %>

			<li>
				<a href="/book/info/id/<%= data[i]['id'] %>">
					<div class="r_img">
						<img src="<%= data[i]['cover'] %>" />
						<span></span>
					</div>
					<div class="r_img_text">
						<h3><%= data[i]['title'] %></h3>
						<p><%= data[i]['intro'] %></p>
						<div class="r_img_other">
							<i><%= data[i]['author'] %></i>
						</div>
					</div>
				</a>
			</li>

        <% } %>    
</script>
<script type="text/html" id="list3">

	<% for(var i = 0; i < data.length; i++){ %>
	<li sbid = "<%= data[i]['bookid'] %>">
				<a href="<%= data[i]['url'] %>">
					<div class="r_img">
						<img src="<%= data[i]['img'] %>" />
											</div>
					<div class="r_img_text">
						<h3><%= data[i]['name'] %></h3>
						<div class="r_img_chaptername">上次读到：<%= data[i]['title'] %></div>
						<div class="r_img_chaptername">更新至：<%= data[i]['lastvolume'] %></div>
						<div class="r_img_other">
						<em>继续阅读</em>						
					</div>
					</div>
				</a>
			</li>

	<% } %> 
	
</script>



<div class="footer_box">
    	<div class="footer_ewm">
                <img id="ewm" alt="" src=""/>
            </div>
    	<div class="footer_txt" style="width: 2.5rem;text-align: center">
<p>工作时间：09：00-18：00<br><br></p>            </div>
</div>
<link rel="stylesheet" href="__PUBLIC__/ieasy/css/vendor.css" />
<link href="__PUBLIC__/ieasy/css/font_apds0v8n2bhp8pvi.css" rel="stylesheet">
<link href="__PUBLIC__/ieasy/css/front.css" rel="stylesheet">
<div style="padding-top: 30px;"></div>
 {block name="include"}{include file="public:tabbar" /}{/block}
{/block}
{block name="script"}
<script type="text/javascript" src="__PUBLIC__/ieasy/js/zepto.min.js?v=2.1.49"></script>
<script type="text/javascript" src="__PUBLIC__/ieasy/js/zepto.cookie.min.js?v=2.1.49"></script>

<!-- 这是zepto插件 -->
<script type="text/javascript" src="__PUBLIC__/ieasy/js/zepto.picLazyLoad.min.js?v=2.1.49"></script>

<script type="text/javascript" src="__PUBLIC__/ieasy/js/common.js?v=2.1.49"></script>
<script type="text/javascript" src="__PUBLIC__/ieasy/js/cps_log.js?v=2.1.49"></script>
<script>

// JavaScript Document
var removeBook = true;

$(function(){
	//编辑最近阅读
	$('.r_img_edit_open').click(function(){
		$('.r_img_list_box').addClass('r_img_list_edit');
	});
	
	//取消编辑最近阅读
	$('.r_img_edit_close').click(function(){
		$('.r_img_list_box').removeClass('r_img_list_edit');
	});
	
	//选中要删除的book
	$('.r_img_list_box').on('click','.r_img_list_edit .r_img_ul a',function(e){
		var $this=$(this),booknum=0;
		$this.toggleClass('r_img_remove_select');
		booknum=$('.r_img_remove_select').length;
		$('.r_book_num em').text('已选中'+booknum+'本');
		if(booknum<=0){
			$('.r_img_list_box').removeClass('r_img_list_edit_remove');
		}else{
			$('.r_img_list_box').addClass('r_img_list_edit_remove');
		}
		
		//不要删 阻止点击a标签跳转
		e.stopPropagation();
		return false;
	});
	
	//确认删除最近阅读
	$('.r_img_edit_remove').click(function(){
		var orma = $('.r_img_remove_select');
		var armbid = [];
		var allblen = parseInt($('.r_book_num strong').attr('totalnum'));
		var ntotalnum = allblen - orma.length;
		for(var i=0; i<orma.length; i++){
			armbid.push($('.r_img_remove_select').eq(i).parent().attr('sbid'));
		}
		if(armbid.length <= 0){
			return false;
		}
		//console.log(armbid);
		//armbid=JSON.stringify(armbid);
		if(removeBook){
			removeBook = false;
			ok=0;
			for(i=0;i<armbid.length;i++)
			{
			$.ajax({
				type: 'POST',
				async: false,
                contentType: 'application/json',
				url: '/api/user/delhistory/id/'+armbid[i],
				success: function (data) {
					removeBook = true;
						$('.r_img_remove_select').parent().remove();
						//删除完成显示取消按钮
						$('.r_img_list_box').removeClass('r_img_list_edit_remove');

						//选中删除的多少本
						$('.r_book_num em').text('已选中0本');
						//共多少本
						$('.r_book_num strong').text('共' + data.totalNum + '本');
						$('.r_book_num strong').attr('totalnum',data.totalNum);

						//小于4本 显示为你推荐
						if(data.totalNum<4){
							$('.r_img_list_other').show();
						}
						if(data.totalNum<=0){
							$('.r_img_list_box').remove();
							$('.content_null_box').show();
						}
						//consoleMain('删除成功');
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					//consoleMain('删除失败,请稍后重试');
					removeBook = true;
				}
				
			});
			setTimeout(function(){
		            console.log("success");
		        },1000); 

			}
			consoleMain('删除成功');
			location.reload();
		}

	});

	scroll(function(direction) {
		if(direction=='down'){
			$('body').removeClass('fixednav');
		}else{
			if(afterScrollTop>100) {
				$('body').addClass('fixednav');
			}else{
				$('body').removeClass('fixednav');
			}
		}
	});
	
})


//滚动滚轮
var afterScrollTop=0;
function scroll( fn ) {
	var beforeScrollTop = $(window).scrollTop(),
		fn = fn || function() {};
	$(window).scroll(function() {
		afterScrollTop = $(window).scrollTop();
		var delta = afterScrollTop - beforeScrollTop;
		if( delta === 0 ) return false;
		fn( delta > 0 ? "down" : "up" );
		beforeScrollTop = afterScrollTop;
	});
}



</script>
<script>




var pagenum=2,
	sBookstop=true,
	sBookstopTime=null,
	pagesize=10,
	block_id = $("#block_id").val(),
	user_id=$.fn.cookie('user_id');


$(function(){

$.ajax({
    url: '/api/index/url_get_ewm/',
	type: 'get',
	dataType:'json',
    success: function (json) {
        $("#ewm").attr('src',json.data); 
    }
});

$.ajax({
            url: '/api/user/history/',
            type: 'post',
			dataType:'json',
			success: function (json) {
				console.log(json);
				if (json.data.length >0) {
					$('#num').html('共'+json.data.length+'本');
					var banner=template('list3',json);
					document.getElementById("recent_ul").innerHTML = banner;
				}
				else{
					$("#kong").css('display','block');
					$("#quanbu").css('display','none');
				}
            }
});
$.ajax({
	url: '/api/index/getbook/',
	type: 'post',
	data:{
		type:3,
		start:0,
		limit:10,
	},
	success: function (data) {

		if (data.code === 1) {
			var banner=template('list2',data);
			document.getElementById("tj1").innerHTML = banner;
		}
	}
});

				
	$('img').picLazyLoad({
		effect : "fadeIn"
	});
	
	
	if(user_id && $('#recent_ul li').length >= pagesize){
		console.log(user_id);
		$(window).scroll(function(){
			var nWinH =  document.documentElement.clientHeight;
			var nScrollTop = (document.body.scrollTop || document.documentElement.scrollTop) + nWinH;
			var nBodyScrollH = document.body.scrollHeight;
			if(sBookstop && nBodyScrollH - nScrollTop < 600){
				bookstoptime();
			}
		});
		
	}
});


	
	
	
</script>
{/block}